package servlet;

import db.DB;
import model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/edituser")//访问的时候给一个地址,高于3.0版本的包才能这么配地址
public class edituser extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setHeader("content-type","text/html;charset=utf-8");
        Integer id=Integer.parseInt(req.getParameter("userid"));
        String roles=req.getParameter("roles");
        Byte permission=Byte.parseByte(req.getParameter("permission"));

        HttpSession session=req.getSession();
        DB DB=new DB();

        if(DB.isop(id)){
            session.setAttribute("message","无法修改管理员账户，修改失败！");

        }
        else{DB.edituser(id,roles,permission);}
        resp.sendRedirect("user.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp); }
}

